package Question12;

import java.util.Vector;

/**
 * Created by lenovo on 2017/3/10.
 */
public class Qyestion12 {

    private void fullPermutation(Vector<Character> sourse,Vector<Character> result){
        if(sourse.size() == 0){
            String str = "";
            for(int i =0;i<result.size();i++){
                str+=result.elementAt(i);
            }
            if(jodgeEquals(str)){
                System.out.println(str.substring(0,3) + " + " + str.substring(3,6) + " = " + str.substring(6,9));
            }
            return;
        }

        for(int i=0;i<sourse.size();i++){
            Vector<Character> tsource = new Vector<>(sourse);
            Vector<Character> tresult = new Vector<>(result);
            tresult.add(sourse.elementAt(i));
            tsource.remove(i);
            new Qyestion12().fullPermutation(tsource,tresult);
        }
    }

    private Boolean jodgeEquals(String str){
        Integer x1 = Integer.parseInt(str.substring(0,3));
        Integer x2 = Integer.parseInt(str.substring(3,6));
        Integer y1 = Integer.parseInt(str.substring(6,9));

        return x1+x2 == y1?Boolean.TRUE:Boolean.FALSE;
    }
    public  static void main(String[] args){
        Vector<Character> sourse = new Vector<>();
        Vector<Character> result = new Vector<>();

        for(int i =1;i<=9;i++){
            sourse.add((char)('0'+i));
        }

         new Qyestion12().fullPermutation(sourse,result);
    }
}
